#! /bin/sh
#
# Fetch rules and targets prior for the "njs" benchmark.
#
# rule_dir: input/njsscan/njsscan/rules/semantic_grep
# target_dir: input/juice-shop
#
# Uses sh because bash is not installed within the semgrep docker container.
#
set -eu

mkdir -p input
cd input

# Obtain a shallow clone of a git repo for a specific commit
shallow_clone() {
  if [ -d "$name" ]; then
    echo "Reusing repo '$name'"
  else
    echo "Obtaining a shallow clone of git repo '$name', commit $commit"
    mkdir -p "$name"
    (
      cd "$name"
      git init
      git remote add origin "$url"
      git fetch --depth 1 origin "$commit"
      git checkout FETCH_HEAD -b tmp
    )
  fi
}

# Obtain semgrep rules
name="njsscan"
url="https://github.com/ajinabraham/njsscan.git"
commit="edc1d0a8b38bfb5421e21665284f83de3dbe636e"
shallow_clone

# Obtain targets
name="dropbox-sdk-js"
url="https://github.com/dropbox/dropbox-sdk-js.git"
commit="268887672a0d7be58ffbfaf832731698e31d792d"
shallow_clone
